<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>票据管理系统</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="stylesheet" href="assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="assets/css/admin.css">
    <link rel="stylesheet" href="assets/css/app.css">
</head>

<body data-type="generalComponents">


<header class="am-topbar am-topbar-inverse admin-header">
    <div id="name">
        <div class="am-collapse am-topbar-collapse" id="topbar-collapse">
            <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list tpl-header-list">
                <li class="am-dropdown" data-am-dropdown data-am-dropdown-toggle>
                    <a class="am-dropdown-toggle tpl-header-list-link" href="javascript:;">
                        <span class="tpl-header-list-user-nick">{{userName}}</span>
                        <span class="tpl-header-list-user-ico"><img src="assets/img/user06.png"></span>
                    </a>
                    <ul class="am-dropdown-content">
                        <li><a href="login.html"><span class="am-icon-power-off"></span> 退出</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</header>
<div class="tpl-page-container tpl-page-header-fixed">
    <div class="tpl-left-nav tpl-left-nav-hover">
        <div class="tpl-left-nav-list">
            <ul class="tpl-left-nav-menu">
                <li class="tpl-left-nav-item">
                    <a href="javascript:;" class="nav-link tpl-left-nav-link-list ">
                        <i class="am-icon-table"></i>
                        <span>凭证管理</span>
                        <i class="am-icon-angle-right tpl-left-nav-more-ico am-fr am-margin-right tpl-left-nav-more-ico-rotate"></i>
                    </a>
                    <ul class="tpl-left-nav-sub-menu">
                        <li>
                            <a href="transfer-list.html">
                                <i class="am-icon-angle-right"></i>
                                <span>转让列表</span>
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="tpl-left-nav-item">
                    <a href="javascript:;" class="nav-link tpl-left-nav-link-list active">
                        <i class="am-icon-wpforms"></i>
                        <span>我的凭证</span>
                        <i class="am-icon-angle-right tpl-left-nav-more-ico am-fr am-margin-right"></i>
                    </a>
                    <ul class="tpl-left-nav-sub-menu" style="display:block">
                        <li>
                            <a href="my-ticket-list.html" class="active">
                                <i class="am-icon-angle-right"></i>
                                <span>我的凭证列表</span>
                            </a>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
    <div class="tpl-content-wrapper">
        <div class="tpl-content-page-title">
            我的凭证列表
        </div>
        <ol class="am-breadcrumb">
            <li class="am-active"><a style="color: #999999;">我的凭证</a></li>
            <li class="am-active">我的凭证列表</li>
        </ol>
        <!--                        开始-->

        <div id="voucher" class="tpl-portlet-components">
            <div class="tpl-block">
                <div class="am-g">
                    <div class="am-u-sm-6 am-u-md-3">
                        <div class="am-input-group am-input-group-sm">
                                <span class="am-input-group-btn">
                                    <span style="font-size: 14px;margin-right: 8px;margin-left: 8px">凭证编号</span>
                                </span>
                            <input type="text" class="am-form-field" placeholder="请输入凭证编号"
                                   style="border: 1px solid #c2cad8;width: 68%;border-radius: 3px;" v-model="no"
                                   @blur="voucherNo">
                        </div>
                    </div>
                    <div class="am-u-sm-6 am-u-md-3">
                        <div class="am-form-group">
                            <span style="font-size: 14px;">开单企业</span>
                            <select v-model="openEnterprise" @change="voucherEnterprise">
                                <option value="">请选择开单企业</option>
                                <option v-for="(op,index) in open">{{op.name}}</option>
                            </select>
                        </div>
                    </div>
                    <div class="am-u-sm-6 am-u-md-3">
                        <div class="am-input-group am-input-group-sm">
                                <span class="am-input-group-btn">
                                    <span style="font-size: 14px;margin-right: 8px;margin-left: 8px;">开单日期</span>
                                </span>
                            <input type="date"
                                   :clearable="true"
                                   placeholder="请选择日期"
                                   style="border: 1px solid #c2cad8;width: 68%;border-radius: 3px;" v-model="openTime"
                                   @change="voucherTime">
                            <!--                         class="am-form-field" data-am-datepicker-->
                        </div>
                    </div>
                    <div class="am-u-sm-6 am-u-md-3">
                        <div class="am-input-group am-input-group-sm">
                                <span class="am-input-group-btn">
                                    <span style="font-size: 14px;margin-right: 8px;margin-left: 8px">凭证金额</span>
                                </span>
                            <input type="text" class="am-form-field" placeholder="最低金额(万)"
                                   style="border: 1px solid #c2cad8;width: 32%;border-radius: 3px;" @blur="min"
                                   v-model="minBalance">
                            <div class="am-form-field"
                                 style="width: 0%; border-radius: 3px;border: none;margin-left: 10px;">~
                            </div>
                            <input type="text" class="am-form-field" placeholder="最高金额(万)"
                                   style="border: 1px solid #c2cad8;width: 32%;border-radius: 3px;margin-left: 20px;"
                                   @blur="max" v-model="maxBalance">
                        </div>
                    </div>
                </div>
            </div>
            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th class="table-title">凭证编号</th>
                                <th class="table-author am-hide-sm-only">凭证金额（元）</th>
                                <th class="table-date am-hide-sm-only">开单企业</th>
                                <th class="table-date am-hide-sm-only">金融机构</th>
                                <th class="table-date am-hide-sm-only">开单日期</th>
                                <th class="table-date am-hide-sm-only">到期日期</th>
                                <th class="table-date am-hide-sm-only">上链地址</th>
                                <th class="table-date am-hide-sm-only">凭证来源</th>
                                <th class="table-date am-hide-sm-only">凭证状态</th>
                                <th class="table-set">操作</th>
                            </tr>
                            </thead>
                            <tbody id="doc-modal-list">
                            <tr v-for="(vou,index) in page.data">
                                <td class="am-hide-sm-only">{{vou.no}}</td>
                                <td class="am-hide-sm-only">{{vou.amount|numFilter}}</td>
                                <td class="am-hide-sm-only">{{vou.enterpriseName}}</td>
                                <td class="am-hide-sm-only">{{vou.institutyName}}</td>
                                <td class="am-hide-sm-only">{{vou.openTime}}</td>
                                <td class="am-hide-sm-only">{{vou.expiryTime}}
                                    <span style="color: #ccc;font-size:12px">剩 {{Math.floor((Date.parse(vou.expiryTime) - Date.parse(new Date())) / (1000 * 3600 * 24))}} 天</span>
                                </td>
                                <td class="am-hide-sm-only">{{vou.address}}</td>
                                <td class="am-hide-sm-only">{{vou.source}}</td>
                                <td class="am-hide-sm-only">{{vou.status}}</td>
                                <td>
                                    <div class="am-btn-toolbar">
                                        <div class="am-btn-group am-btn-group-xs">
                                            <a href="#">
                                                <span class="am-text-secondary" style="cursor:pointer"
                                                      @click.prevent="details(vou.id)"><span></span>
                                                        详情</span></a>
                                            <a href="#" v-if="vou.status === '未转让'">
                                                <span class="am-text-secondary" style="cursor:pointer"
                                                      @click.prevent="transfer(vou.id)"><span></span>
                                                            转让</span></a>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        <div class="am-cf">
                            <div class="am-fr">
                                <ul class="am-pagination tpl-pagination">
                                    <li><a href="#" @click.prevent="toPage(page.currentPage - 1)">«</a></li>
                                    <li><a href="#" @click.prevent="toPage(page.currentPage - 2)"
                                           v-if="page.currentPage - 2 > 0">{{page.currentPage - 2}}</a></li>
                                    <li><a href="#" @click.prevent="toPage(page.currentPage - 1)"
                                           v-if="page.currentPage - 1 > 0">{{page.currentPage - 1}}</a></li>
                                    <li class="am-active"><a href="#" @click.prevent="toPage(page.currentPage)"
                                                             v-if="page.currentPage == page.currentPage">{{page.currentPage}}</a>
                                    </li>
                                    <li><a href="#" @click.prevent="toPage(page.currentPage + 1)"
                                           v-if="page.currentPage + 1 <= page.lastPage">{{page.currentPage + 1}}</a>
                                    </li>
                                    <li><a href="#" @click.prevent="toPage(page.currentPage + 2)"
                                           v-if="page.currentPage + 2 <= page.lastPage">{{page.currentPage + 2}}</a>
                                    </li>
                                    <li><a href="#" @click.prevent="toPage(page.currentPage + 1)">»</a></li>
                                </ul>
                            </div>
                        </div>
                        <hr>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="assets/js/vue.js"></script>
<script src="assets/js/axios.min.js"></script>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/amazeui.min.js"></script>
<script src="assets/js/app.js"></script>

<script>
    const voucher = new Vue({
        el: "#voucher",
        data: {
            no: "",
            openEnterprise: "",
            open: {},
            openTime: "",
            page: {},
            minBalance: "",
            maxBalance: "",
            pageNum: "",
            userName: "",
            voucherId: {}
        },
        methods: {
            public() {
                let enterpriseId = JSON.parse(window.sessionStorage.getItem("loginEnterpriseId"));
                let _this = this;
                let formData = new FormData();
                formData.append("no", _this.no);
                formData.append("enterpriseName", _this.openEnterprise);
                formData.append("openTime", _this.openTime);
                formData.append("min", _this.minBalance);
                formData.append("max", _this.maxBalance);
                formData.append("currentPage", _this.pageNum);
                formData.append("enterpriseId", enterpriseId);
                axios({
                    method: "post",
                    url: "admin/listAll.vou",
                    data: formData,
                }).then(function (response) {
                    if (response.data.code === 1001) {
                        console.log(response.data)
                        alert("输入最小金额不合法")
                        _this.minBalance="";
                    } else if (response.data.code === 1002) {
                        console.log(response.data)
                        alert("输入最大金额不合法")
                        _this.maxBalance="";
                    } else {
                        let data = response.data;
                        _this.page = data.value;
                    }
                });
            },
            /**
             * 分页
             * @param pageNum
             */
            toPage(pageNum) {
                let _this = this;
                if (pageNum == 0) {
                    pageNum = 1;
                }
                if (pageNum > this.page.lastPage) {
                    pageNum = this.page.lastPage;
                }
                _this.pageNum = pageNum;
                this.public();
            },
            /**
             * 凭证编号
             */
            voucherNo() {
                let _this = this;
                _this.pageNum = "1";
                // alert(this.no);
                this.public();
            },
            /**
             * 开单企业
             */
            voucherEnterprise() {
                let _this = this;
                _this.pageNum = "1";
                // alert(this.openEnterprise)
                this.public();
            },

            /**
             * 日期
             */
            voucherTime() {
                let _this = this;
                _this.pageNum = "1";
                // alert(this.openTime)
                this.public();
            },
            /**
             * 最小金额
             */
            min() {
                let _this = this;
                _this.pageNum = "1";
                this.public();
            },
            /**
             * 最大金额
             */
            max() {
                let _this = this;
                _this.pageNum = "1";
                this.public();
            },
            /**
             * 详情的触发事件
             * @param id Voucher表的id
             */
            details(id) {
                let _this = this;
                _this.nowId = id;
                console.log(_this.nowId)
                location.href = "my-ticket-detail.html?id=" + id;
            },
            /**
             * 转让的触发事件
             * @param id Voucher表的id
             */
            transfer(id) {
                location.href = "ticket-transfer.html?id=" + id;
            }
        },
        created() {
            // let start = location.href.lastIndexOf("=");
            // let nowId = location.href.substring(start + 1);
            // console.log(start)
            // console.log(nowId)
            let enterpriseId = JSON.parse(window.sessionStorage.getItem("loginEnterpriseId"));
            this.userName = JSON.parse(window.sessionStorage.getItem("userName"));
            console.log("登录id：" + enterpriseId)
            if (enterpriseId === null) {
                location.href = "login.html";
            }
            // console.log(this.userName);
            let _this = this;
            let formData = new FormData();
            formData.append("no", _this.no);
            formData.append("enterpriseName", _this.openEnterprise);
            formData.append("openTime", _this.openTime);
            formData.append("min", _this.minBalance);
            formData.append("max", _this.maxBalance);
            formData.append("currentPage", _this.pageNum);
            formData.append("enterpriseId", enterpriseId);
            axios({
                method: "post",
                url: "admin/listAll.vou",
                data: formData,
            }).then(function (response) {
                // if(response.data.code === 1001){
                //     console.log(response.data)
                // alert("111111")
                // }else{
                let data = response.data;
                // console.log(data)
                _this.page = data.value;
                // }
            });
            axios.get("admin/openEnterprise.vou?enterpriseId=" + enterpriseId).then(function (response) {
                let data = response.data;
                _this.open = data.value;
            });
        },
        filters: {
            numFilter: function (value) {
                return parseFloat(value).toFixed(2);
            }
        }
    });
    const name1 = new Vue({
        el: "#name",
        data: {
            userName: "",
        },
        created() {
            this.userName = voucher.userName
        }
    })
</script>
</body>

</html>